import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class AnimationRoute extends StatefulWidget {
  @override
  _AnimationRouteState createState() => _AnimationRouteState();
}

class _AnimationRouteState extends State<AnimationRoute>
    with SingleTickerProviderStateMixin {
  Animation<double> _animationDouble;
  AnimationController animationControllerDouble;
  AnimationStatus _animationStatusDouble;
  double _animationValues;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    animationControllerDouble =
        AnimationController(vsync: this, duration: Duration(seconds: 5));
    CurvedAnimation curvedAnimation = CurvedAnimation(
        curve: Curves.bounceInOut, parent: animationControllerDouble);
    _animationDouble = Tween(begin: 50.0, end: 150.0).animate(curvedAnimation)
      ..addListener(() {
        setState(() {
          _animationValues = _animationDouble.value;
        });
      })
      ..addStatusListener((status) {
        setState(() {
          _animationStatusDouble = status;
        });
        switch (status) {
          case AnimationStatus.completed:
            animationControllerDouble.reverse();
            break;
          case AnimationStatus.dismissed:
            animationControllerDouble.forward();
            break;
          case AnimationStatus.forward:
            break;
          case AnimationStatus.reverse:
            break;
        }
      });
    animationControllerDouble.forward();
  }

  @override
  void dispose() {
    animationControllerDouble.stop();
    animationControllerDouble.dispose();
    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SafeArea(
          child: Column(
            children: <Widget>[
              Text('values = $_animationValues'),
              Text('status = $_animationStatusDouble'),
              Container(
                width: _animationValues,
                height: _animationValues,
                child: FlutterLogo(),
              ),
              AnimatedLogo(animation: _animationDouble,),
              GrowTransition(widget: LogoWidget(),animation: _animationDouble,)
            ],
          ),
        ),
      ),
    );
  }
}

class AnimatedLogo extends AnimatedWidget {
  AnimatedLogo({Key key, Animation<double> animation})
      : super(key: key, listenable: animation);

  @override
  Widget build(BuildContext context) {
    final Animation<double> animation = listenable;
    // TODO: implement build
    return Center(
      child: Container(
        margin: EdgeInsets.symmetric(vertical: 10),
        height: animation.value,
        width: animation.value,
        child: FlutterLogo(),
      ),
    );
  }
}

class LogoWidget extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.symmetric(vertical: 10),
      child: FlutterLogo(),
    );
  }
}

class GrowTransition extends StatelessWidget{

  Widget widget;
  Animation<double> animation;
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(
      child: AnimatedBuilder(
        animation: animation,
        builder: (context, child) {
          return Container(
            height: animation.value,
            width: animation.value,
            child: widget,
          );
        },
      ),
    );
  }
  GrowTransition({this.widget, this.animation});
}
